from www.util.operation_execl import OperationExcel
from www.data import  data_config
from www.util.operation_json import OperationJson

class GetData:

    def __init__(self):
        self.excel = OperationExcel()

    def get_case_lines(self):
        return self.excel.get_lines()

    def get_is_run(self,row):
        flag = None
        col = int(data_config.get_run())
        run_mode = self.excel.get_cell_value(row,col)
        if run_mode == 'yes':
            flag = True
        else:
            flag = False
        return flag

    def is_header(self,row):
        col = int(data_config.get_header())
        header = self.excel.get_cell_value(row,col)
        if header == 'yes':
            return  data_config.get_header_value()

        else:
            return None

    def get_request_method(self,row):
        col = int(data_config.get_run_way())
        request_method = self.excel.get_cell_value(row,col)
        return request_method

    def get_url(self,row):
        col = int(data_config.get_url())
        url = self.excel.get_cell_value(row,col)
        return url

    def get_request_data(self,row):
        col = int(data_config.get_data())
        data = self.excel.get_cell_value(row,col)
        if data =='':
            return None
        return data

    def get_data_for_json(self,row):
        open_json = OperationJson()
        request_data = open_json.get_data(self.get_request_data(row))
        return request_data

    def get_expect(self,row):
        col = int(data_config.get_expect())
        expect = self.excel.get_cell_value(row,col)
        if expect == '':
            return None
        return expect

    def write_result(self,row,value):
        col = int(data_config.get_result())
        self.excel.write_value(row,col,value)




